package com.kfzx.www.mycalendardemo;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.joda.time.DateTime;

import java.util.ArrayList;
import java.util.List;

public class Fragment2 extends Fragment {
    private static final String TAG = "Fragment2";
    private List<Fragment> mFragmentList = new ArrayList<>();
    private ViewPager mViewPager;
    private TextView mTextView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment2, container, false);

        mViewPager = (ViewPager) view.findViewById(R.id.view_pager);
        initFragment();
        CustomFragmentPagerStateAdapter adapter = new CustomFragmentPagerStateAdapter(getChildFragmentManager(), mFragmentList);
        mViewPager.setAdapter(adapter);
        return view;
    }

    private void initFragment() {
        DateTime dateTime = new DateTime();

        for (int i = 6; i > 1; i--) {
            String date = dateTime.minusMonths(i).toString("yyyy-MM-dd");
            mFragmentList.add(MonthFragment.newInstance(date));
        }
        mFragmentList.add(MonthFragment.newInstance(dateTime.toString("yyyy-MM-dd")));
        for (int i = 1; i <= 6; i++) {
            String date2 = dateTime.plusMonths(i).toString("yyyy-MM-dd");
            mFragmentList.add(MonthFragment.newInstance(date2));
        }
    }

}
